package guoanmaker.operator.business.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorContractDownloadCount;
import java.lang.String;
import java.util.List;

/**
 * 
* @ClassName: OperatorContractDownloadCountRepository.java 
* @Description: 合同下载计量repository
* @author Cancerl
* @date 2018年1月5日
*  
 */
public interface OperatorContractDownloadCountRepository extends JpaRepository<OperatorContractDownloadCount, String>,JpaSpecificationExecutor<OperatorContractDownloadCount>{
	//根据合同名称及合同类型id查询合同下载信息   下载信息按下载量倒叙排列	Pageable分页查询
	Page<OperatorContractDownloadCount> findAllByContractNameLikeAndTypeIdOrderByCountDesc(Pageable pageable ,String contractName, String typeId);
	Page<OperatorContractDownloadCount> findAllByContractNameLikeAndTypeIdAndGuideNotOrderByCountDesc(Pageable pageable ,String contractName, String typeId,String guide);
	Page<OperatorContractDownloadCount> findAllByContractNameLikeAndTypeIdAndGuideEqualsOrderByCountDesc(Pageable pageable ,String contractName, String typeId,String guide);
	//合同类型为空  按照合同名称查询
	Page<OperatorContractDownloadCount> findAllByContractNameLikeOrderByCountDesc(Pageable pageable ,String contractName);
	Page<OperatorContractDownloadCount> findAllByContractNameLikeAndGuideNotOrderByCountDesc(Pageable pageable ,String contractName,String guide);
	Page<OperatorContractDownloadCount> findAllByContractNameLikeAndGuideEqualsOrderByCountDesc(Pageable pageable ,String contractName,String guide);
	
	//通过合同id获取合同计量对象
	List<OperatorContractDownloadCount> findByContractId(String contractid);
	
	//涉及到合同信息修改   合同信息修改后需要对相应下载记录做出修改
	//合同类型修改
	@Transactional
	@Modifying
	@Query("update OperatorContractDownloadCount set typeName = ?2 where typeId = ?1")
	void updateContractTypeName(String typeId,String typeName);
	//合同名称修改
	@Transactional
	@Modifying
	@Query("update OperatorContractDownloadCount set contractName = ?2 where contractId = ?1")
	void updateContractName(String contractId , String ContractName);
}
